	$(document).ready(function() {
			
					
		// validate profile form on keyup and submit
			$("#profilefrm").validate({
			
			 errorElement: "span", 
			 
			 
			//set the rules for the fields
			rules: {
			
				name: {
					required: true
				},
				email: {
					required: true,
					email: true
				},
				password: {
					required: true,
					minlength: 8,
					maxlength:20
				},
				contactno: {
					required: true
				},
				country: {
					required: true
				},
				address: {
					required: true
				},
				terms: {
					required: true
				}
				
			},
			//set messages to appear inline
			messages: {
			
				name: {
					required: " Name is required",
				},
				
				password: {
					required: "Provide a password.",
					minlength: "Your password must be at least 5 characters long",
					maxlength: "Password can not be more than 15 characters"
				},
				
				email:  {
					required: '<br>Email address is required',
					email: '<br>Please enter a valid email address',
					remote: '<br>Email already used. Log in to your existing account.'
				},
				contactno: "<br>Provide a contact number.",
				country: "Country is required.",
				address: "Address is required.",
				terms: "You must accept our terms & conditions."
				
			},
			
		errorPlacement: function(error, element) {
				if ( element.is(":checkbox") )
					error.insertAfter( '#terms_error' );
				else
					error.appendTo($(element).parents('tr').find('td.info'));     
			}

		});
		// validate contact form on keyup and submit
			$("#classifiedpostfrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
			
				title: {
					required: true
				},
				selectCatg: {
					required: true
				},
				description: {
					required: true
				},
				pprice: {
					required: true
				},
				contact_person: {
					required: true
				},
				contact_no: {
					required: true
				},
				contact_email: {
					required: true
				}
				
			},
			//set messages to appear inline
			messages: {
				title: {
					required: "title is required"
				},
				description: {
					required: "Please write descriptions."
				},
				selectCatg: {
					required: "Please choose category."
				},
				pprice: "Price is required.",
				contact_person: "<br>Please provide contact name.",
				contact_no: "Please provide a contact number.",
				contact_email: "Please provide an email."
			},
			
		errorPlacement: function(error, element) { 
				if (element.attr("name") == "selectCatg") {
					error.appendTo("#errorCatg");
				} else{  
				error.appendTo(element.parent());
				}
			}
		});
		//validate propertyform frm
			$("#propertyfrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
			
				ptitle: {
					required: true
				},
				pdescriptions: {
					required: true
				},
				bedrm: {
					required: true
				},
				bathrm: {
					required: true
				},
				livingrm: {
					required: true
				},
				contact_person: {
					required: true
				},
				contact_no: {
					required: true
				},
				contact_email: {
					required: true,
					email: true
				},
				propType:{
					required: function () {
                       return ($("#propType").val() == '');
					}
				},
				othcatg: {
					required: function() {
						return  $("#propType option:selected").text() == 'Others'
						//return $("#propType").val() == '5';
					}
				}
				
			},
			//set messages to appear inline
			messages: {
				ptitle: {
					required: "title is required"
				},
				propType: {
					required: "<br>Select a category"
				},
				pdescriptions: {
					required: "Please write descriptions"
				},
				othcatg: {
					required: "<br>Provide other property type descriptions"
				},
				bathrm: {
					required: "<br>No of bed room"
				},
				bedrm: {
					required: "<br>No of bath room"
				},
				livingrm: {
					required: "<br>No of living room"
				},
				contact_person: "<br>Please provide contact name",
				contact_no: "<br>Please provide a contact number",
				contact_email: {
					required: "<br>We need your email address to contact you",
					email: "Your email address must be in the format of name@domain.com"
				}
			},
			
		errorPlacement: function(error, element) {   
				if (element.attr("name") == "pprice") {
					error.appendTo("#pricediv");
				} else if (element.attr("name") == "description"){
					error.appendTo("#descriptiondiv");
				}
				else {
					error.appendTo(element.parent()) ;
				}
			}
		});
		//validate automobile frm
			$("#automobilefrm").validate({
			
			  errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
			
				autotitle: {
					required: true
				},
				adescriptions: {
					required: true
				},
				autoprice: {
					required: true
				},
				contact_person: {
					required: true
				},
				contact_no: {
					required: true
				},
				contact_email: {
					required: true,
					email: true
				},
				selectType:{
					required: function () {
                       return ($("#selectType").val() == "");
					}
				},
				brand: {
					required: function() {
						return ($("#brand").val() == "");
					}
				}
				
			},
			//set messages to appear inline
			messages: {
				autotitle: {
					required: "title is required"
				},
				selectType: {
					required: "Select type of your vehicle"
				},
				brand: {
					required: "Select brand of your vehicle"
				},
				adescriptions: {
					required: "<br>Please write descriptions"
				},
				autoprice: "<br>Price is required",
				contact_person: "<br>Please provide contact name",
				contact_no: "<br>Please provide a contact number",
				contact_email: {
					required: "<br>We need your email address to contact you",
					email: "Your email address must be in the format of name@domain.com"
				}
			},
			
		errorPlacement: function(error, element) {   
				if (element.attr("name") == "autoprice") {
					error.insertAfter("#pricediv");
				} 
				else if (element.attr("name") == "adescriptions") {
					error.insertAfter("#descErr");
				} 
				else {
					error.appendTo(element.parent()) ;
				}
			}
		});
		//validate login frm
		$("#loginfrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
				username: {
					required: true,
					email: true
				},
				password: {
					required: true,
				}
			},
			//set messages to appear inline
			messages: {
				username: {
					required: "Email is required to login"
				},
				password: {
					required: "Please provide password."
				}
			},
			
		errorPlacement: function(error, element) {   
				error.appendTo(element.parent());     
			}
		});

		$("#resetfrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			//set messages to appear inline
			messages: {
				email: {
					required: "Email is required for password reset",
					email: "Please enter valid email"
				}
			},
			
		errorPlacement: function(error, element) {   
				error.appendTo(element.parent());     
			}
		});
		//validate article frm
		$("#articlefrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
				articletitle: {
					required: true
				},
				entry: {
					required: true
				}
			},
			//set messages to appear inline
			messages: {
				articletitle: {
					required: "Title is required for article"
				},
				entry: {
					required: "Please write entry."
				}
			},
			
		errorPlacement: function(error, element) {   
				error.appendTo(element.parent());     
			}
		});
		//validate article frm
		$("#contactfrm").validate({
			
			 errorElement: "span", 
			 
			//set the rules for the fields
			rules: {
				name: {
					required: true
				},
				email: {
					required: true
				},
				message: {
					required: true
				},
				terms: {
					required:true
				}
			},
			//set messages to appear inline
			messages: {
				name: {
					required: "Title is required"
				},
				email: {
					required: "Email is required."
				},
				message: {
					required: "Enter your message."
				},
				terms: {
					required: "Accept terms and conditions"
				}
			},
			
		errorPlacement: function(error, element) {  
				if ( element.is(":checkbox") )
					error.insertAfter( '#terms_error' );
				else 
				error.appendTo(element.parent());     
			}
		});
	});